repos <- "http://cran.us.r-project.org"
repos_new <- "https://cloud.r-project.org/src/contrib"

packages <- list(
  list(name="nloptr"),
  list(name="foreach"),
  list(name="doParallel")
)

for (i in 1:length(packages)) {
  package <- packages[[i]]
  installed <- require(package$name, character.only=TRUE)
  if (installed) {
    next
  }

  install.packages(package$name, repos=repos)
  installed <- require(package$name, character.only=TRUE)
  if (!installed) {
   install.packages("https://cloud.r-project.org/src/contrib/nloptr_2.0.3.tar.gz")
   install.packages("https://cloud.r-project.org/src/contrib/iterators_1.0.14.tar.gz")
   install.packages("doParallel")
  }
}

